package com.ck.util;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.poi.excel.BigExcelWriter;
import cn.hutool.poi.excel.ExcelUtil;

import java.util.ArrayList;
import java.util.List;

/**
 * 连续数字, 排除中间数字生成excel
 */
public class ExcludeNumGenerateKey {

    private static final String zero = "000000000000";

    public static void main(String[] args) {
        String fileName = "D:/temp/label1.xlsx";
        String pakNum = "1";
        int startNum = 1;
        int endNum = 10000;
        int totalNumLen = String.valueOf(endNum).length()+1;
        String[] excludeNum = new String[]{"4","7"};
        executeLabel(startNum,endNum,excludeNum,totalNumLen,pakNum,fileName);
    }
    /**
     *
     * @param startNum 总数
     * @param endNum 总数
     * @param excludeNum 排除数字
     */
    private static void executeLabel(int startNum, int endNum, String[] excludeNum, int totalNumLen,String pakNum,String fileName) {
        List<String> row1 = CollUtil.newArrayList("SN", "Head[16]", "TagID[16]", "TagID[10]","Box");
        List<String> dataRow;
        List<List<String>> allRows = new ArrayList<>();
        allRows.add(row1);
        int sort = 1;
        for (int i = startNum; i <= endNum; i++) {
            String strI = String.valueOf(i);
            if(!strI.contains(excludeNum[0]) && !strI.contains(excludeNum[1])) {
                dataRow = new ArrayList<>();
                int strLen = strI.length();
                if(strLen < totalNumLen) {
                    strI = zero.substring(0,totalNumLen-strLen) + strI;
                }
                dataRow.add(String.valueOf(sort++));
                dataRow.add("30");
                dataRow.add(strI);
                System.out.println(strI);
                dataRow.add("202203092037");
                dataRow.add(pakNum);

                allRows.add(dataRow);
            }
        }
        writeExcel(allRows,fileName);
    }
    /**
     *
     * @param startNum 总数
     * @param endNum 总数
     * @param excludeNum 排除数字
     */
    private static void executePlate(int startNum, int endNum, String[] excludeNum, int totalNumLen,String pakNum,String fileName) {
        List<String> row1 = CollUtil.newArrayList("序号", "包装盒号", "车牌号", "国标/非国标");
        List<String> dataRow;
        List<List<String>> allRows = new ArrayList<>();
        allRows.add(row1);
        int sort = 1;
        for (int i = startNum; i <= endNum; i++) {
            String strI = String.valueOf(i);
            if(!strI.contains(excludeNum[0]) && !strI.contains(excludeNum[1])) {
                dataRow = new ArrayList<>();
                int strLen = strI.length();
                if(strLen < totalNumLen) {
                    strI = zero.substring(0,totalNumLen-strLen) + strI;
                }
                dataRow.add(String.valueOf(sort++));
                dataRow.add(pakNum);
                dataRow.add(strI);
                System.out.println(strI);
                dataRow.add("非国标");
                    allRows.add(dataRow);
            }
        }
        writeExcel(allRows,fileName);
    }

    private static void writeExcel(List<List<String>> rows, String fileName) {
        BigExcelWriter writer= ExcelUtil.getBigWriter(fileName);
        // 一次性写出内容，使用默认样式
        writer.write(rows);
        // 关闭writer，释放内存
        writer.close();
    }
}